package com.guestbook.service;

import java.util.Map;

import javax.ejb.Stateless;

import com.common.util.ObjectUtils;
import com.core.service.AppBaseService; 
import com.guestbook.entity.TB_GUESTBOOK;

/**
 *  
 */
@Stateless
public class SVC_GUESTBOOK extends AppBaseService implements SVC_GUESTBOOKRemote, SVC_GUESTBOOKLocal {

	@Override
	public Map ADD_GUESTBOOK(Map param) {
		TB_GUESTBOOK tdo = ObjectUtils.mapToJavaBean(param, TB_GUESTBOOK.class); 
		tdo.setID(tdo.uuid());
		tdo.setUSID(getOpid(param));
		tdo.setCREATE_TIME(getOpTime(param));
		tdo.setOP_ITEM(getOpTime(param));
		tdo.setOPID(getOpid(param)); 
		if(tdo.getFIRST_MES_ID()==null){
		   tdo.setFIRST_MES_ID(tdo.getID());
		} 
		getJpaDao().save(tdo);
		return ObjectUtils.javaBeanToMap(tdo);
	}

	@Override
	public Map UPD_GUESTBOOK(Map param) {
		TB_GUESTBOOK tdo = ObjectUtils.mapToJavaBean(param, TB_GUESTBOOK.class);  
		tdo.setOP_ITEM(getOpTime(param));
		tdo.setOPID(getOpid(param)); 
		
		TB_GUESTBOOK po = getJpaDao().find(TB_GUESTBOOK.class,tdo.getID());  
		if(!po.getUSID().equals(tdo.getUSID())){
			throw new RuntimeException("只有本人可以修改！");
		}
		
		ObjectUtils.copyJavaBeanToBean(tdo, po, "CREATE_TIME","FIRST_MES_ID","LAST_MES_ID"); 
		getJpaDao().update(po);
		return ObjectUtils.javaBeanToMap(po);
	}

	@Override
	public void DEL_GUESTBOOK(Map param) {
		// TODO Auto-generated method stub
		
	}
  
}
